// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email support@swagger.io

// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html

// @termsOfService http://swagger.io/terms/
package main

import (
	_ "dougan/routers"
	"fmt"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/logs"
	_ "github.com/astaxie/beego/logs"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
)

func initDb() {
	conf := []string{
		beego.AppConfig.String("mysql::user"),
		beego.AppConfig.String("mysql::password"),
		beego.AppConfig.String("mysql::host"),
		beego.AppConfig.String("mysql::port"),
		beego.AppConfig.String("mysql::db"),
	}
	uri := fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=utf8", conf[0], conf[1], conf[2], conf[3], conf[4], )

	orm.RegisterDriver("mysql", orm.DRMySQL)
	orm.RegisterDataBase("default", "mysql", uri)

	orm.RunSyncdb("default", false, true)
}

func initLog() {
	logs.SetLogger("console")
	logs.SetLevel(beego.LevelDebug)
	logs.EnableFuncCallDepth(true)
}

func init() {
	// ORM
	initDb()
	// 日志
	initLog()

}

func main() {
	if beego.BConfig.RunMode == "dev" {
		beego.BConfig.WebConfig.DirectoryIndex = true
		beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
	}
	beego.Run()

}
